package com.bolt.report.business.modules;

import com.bolt.common.utils.RandomUtil;
import com.bolt.convention.data.ResultMessage;
import com.bolt.convention.data.Results;
import com.bolt.report.business.test.ProductBean;
import com.bolt.report.business.test.TestTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Controller()
@RequestMapping({"/bolt/report"})
public class TestController {

    @Autowired
    private TestTableService testTableService;

    @GetMapping("/getData")
    @ResponseBody
    public ResultMessage get() {
        String[] product = new String[]{"香焦", "苹果", "荔枝", "香梨", "葡萄", "提子"};
        String[] area = new String[]{"河南", "河北", "湖南", "四川"};
        List<ProductBean> datas = new ArrayList<>();
        for (int i = 0; i < 300; i++) {
            ProductBean productBean = new ProductBean();
            productBean.setProNum(String.valueOf(i));
            productBean.setArea(area[RandomUtil.randomInt(0, 4)]);
            productBean.setProduct(product[RandomUtil.randomInt(0, 5)]);
            productBean.setQuantity(new BigDecimal(RandomUtil.randomInt(1, 100)));
            productBean.setPrice(new BigDecimal(RandomUtil.randomInt(20, 100)));
            datas.add(productBean);
        }
        return Results.success(datas);
    }

    @GetMapping("/insertData")
    public void insertData() {
        testTableService.add();
    }


}